package com.boot.ch2;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @author onlyone
 */

@Configuration
public class CarConfig {

    private List<Car> carList = new ArrayList<>();

    // 方法一：构造器注入， 与下面的@Autowired，功能一样
    // public CarConfig(List<Car> carList){
    // System.out.println("CarConfig 构造器开始执行。。。。");
    // this.carList = carList;
    // }

    @Autowired(required = false)
    public void setCars(List<Car> cars) {
        if (cars != null && !cars.isEmpty()) {
            carList.addAll(cars);
        }
    }

    public List<Car> getCarList() {
        return carList;
    }
}
